/*
 * @author Javier A. Ramírez M.
 * jaramirez85@yahoo.es
 */

package com.jav;

import com.jav.inter.Constantes;
import com.sun.lwuit.Button;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Graphics;
import com.sun.lwuit.Painter;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.geom.Rectangle;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Style;
/**
 *
 * @author Javier
 */
public class InicoForm extends Form implements Constantes{


    public InicoForm(){
        super("...:*:...");
        setGlassPane(new TextPainter("CAPMOVIL 1.7"));
        
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        addComponent(createButton(EMPRESA));
        addComponent(createButton(EMPLEADO));
        addComponent(createButton(ID_EMPLEADO));
        setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 500));
        setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 500));
        Style s = new Style();
        s.setBgTransparency(10);
        setTitleStyle(s);
        setSoftButtonStyle(s);
    }

    private Button createButton(String name) {
        Button boton = new Button(name){

            public void startTicker(long delay, boolean rightToLeft) {
                super.startTicker(100, true);
            }

        };
        Font textFont = Font.createSystemFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM);
        boton.getStyle().setFont(textFont, true);
        //boton.getStyle().setMargin(3, 3, 8, 8);
        boton.getStyle().setBgTransparency(50, false);
        boton.getStyle().setBgColor(0xFF8C00);
        boton.getStyle().setFgColor(0x000000);
        //boton.getStyle().setFgSelectionColor(0xFF0000, true);
        //boton.getStyle().setBgSelectionColor(0x1ECF35);
        boton.setAlignment(CENTER);
        return boton;
    }



}

class TextPainter implements Painter{
  private String text;
  TextPainter(String text)
  {
    //set the text to be written
    this.text = text;
  }
  public void paint(Graphics g, Rectangle rect)
  {
    //get the dimension
    //of background
    int wd = rect.getSize().getWidth();
    int ht = rect.getSize().getHeight();
    //create and set font for text
    Font textFont = Font.createSystemFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_LARGE);
    g.setFont(textFont);
    //set text color
    g.setColor(0x0000aa);
    //position text slightly below centerline
    //int textX = wd/2 - textFont.stringWidth(text)/2;
    int textX = wd - textFont.stringWidth(text);
    int textY = ht - textFont.getHeight()-25;
    //write text
    g.drawString(text,  textX, textY);
  }
}



